package com.ld.security.common.tomcat.base.api;

import com.ld.security.common.core.base.ETreeEntity;
import com.ld.security.common.mybatis.base.po.EntitysPo;
import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.service.ITreeService;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.mybatis.base.vo.PageVo;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 基本树控制器
 *
 * @param <E>
 */
public abstract class TreeApi<E extends ETreeEntity<E>> extends SuperApi<E> {

    @Autowired
    private ITreeService<E> iTreeServiceI;



    @AjaxLogKey
    @RequestMapping(value = "/saveTree", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("修改一颗树")
    public DataVo<PageVo<E>> saveTree(@RequestBody EntitysPo<E> po) {
       int total= iTreeServiceI.saveTree(po.getList());
        return DataVo.ofMsg("成功修改："+total+"调试数据");
    }

    @AjaxLogKey
    @RequestMapping(value = "/pageTree", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("树分页查询")
    public DataVo<PageVo<E>> pageTree(@RequestBody PagePo<E> po) {
        PageVo<E> page = iTreeServiceI.pageTree(po);

        PageVo vo = page;
        DataVo dataVo =  DataVo.of(vo);
        return dataVo;
    }

    @AjaxLogKey
    @RequestMapping(value = "/getTree", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("得到树")
    public DataVo<PageVo<E>> getTree() {
        PageVo<E> page = iTreeServiceI.getTree();
        PageVo vo =page;
        DataVo dataVo =  DataVo.of(vo);
        return dataVo;
    }

}
